﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Brilliants.UI
{
    /// <summary>
    /// NbProgressBar.xaml 的交互逻辑
    /// </summary>
    public partial class NbProgressBar : UserControl
    {
        public NbProgressBar()
        {
            InitializeComponent();
        }





        public double Value
        {
            get { return (double)GetValue(ValueProperty); }
            set 
            {
                if (value < 0)
                    SetValue(ValueProperty, 0d);
                else if (value > 100)
                    SetValue(ValueProperty, 100d);
                else
                    SetValue(ValueProperty, value);

                if (value >= 100)
                    BarBrush = BarBrush = UIResource.GetBrush("Nb.ProgressBar.OkBrush");
                else
                    BarBrush = BarBrush = UIResource.GetBrush("Nb.ProgressBar.OkBrush");
            }
        }

        // Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(double), typeof(NbProgressBar), new FrameworkPropertyMetadata(0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ValuePropertyChangedCallback));


        public static void ValuePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var npb = (NbProgressBar)d;
            npb.Value = (double)e.NewValue;
        }



        public Brush BarBrush
        {
            get { return (Brush)GetValue(BarBrushProperty); }
            set { SetValue(BarBrushProperty, value); }
        }

        // Using a DependencyProperty as the backing store for BarBrush.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BarBrushProperty =
            DependencyProperty.Register("BarBrush", typeof(Brush), typeof(NbProgressBar), new PropertyMetadata(UIResource.GetBrush("Nb.ProgressBar.NormalBrush")));




        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(NbProgressBar), new PropertyMetadata(string.Empty));


    }
}